﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.IO;
using System.Windows.Forms;

namespace codedynamiks_mes_baguio
{
    static class Common
    {
        /// <summary>
        /// Reference to the parent Form
        /// </summary>
        public static frmMain PARENT;
        /// <summary>
        /// Application name. Change to your desired name.
        /// </summary>
        public static string APPNAME = "mes_baguio";
        /// <summary>
        /// Application settings
        /// </summary>
        public static CodeDynamiksEngine.ConfigCache CFG = new CodeDynamiksEngine.ConfigCache("settings", "Settings file");
        /// <summary>
        /// Application local path
        /// </summary>
        public static string LOCPATH = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + APPNAME;
        /// <summary>
        /// Login flag
        /// </summary>
        public static bool LOGGED = false;
        /// <summary>
        /// Apply the application settings.
        /// <para>Implement all settings using this method.</para>
        /// </summary>
        public static void ApplySettings()
        {
            try
            {
                //Apply the screen mode
                if (Common.CFG.CheckKey("FULLSCREEN"))
                {
                    bool fs = bool.Parse(Common.CFG.Read("FULLSCREEN").ToString());
                    if (fs == true)
                        PARENT.WindowState = FormWindowState.Maximized;
                    else
                        PARENT.WindowState = FormWindowState.Normal;
                    PARENT.Refresh();
                }
                //Other settings to apply goes here...
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
    /// <summary>
    /// MessageBox wrapper
    /// </summary>
    public static class Confirm
    {
        /// <summary>
        /// Simplified question dialog with yes/no buttons and question mark icon.
        /// </summary>
        /// <param name="title">Title of the dialog</param>
        /// <param name="msg">Dialog message</param>
        /// <returns>Yes or No</returns>
        public static DialogResult Question(string title, string msg)
        {
            return MessageBox.Show(msg, title, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }
        /// <summary>
        /// Simplified error dialog with Ok button and error icon.
        /// </summary>
        /// <param name="title">Title of the dialog</param>
        /// <param name="msg">Dialog message</param>
        /// <returns>Ok</returns>
        public static DialogResult Error(string title, string msg)
        {
            return MessageBox.Show(msg, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        /// <summary>
        /// Simplied Ok/Cancel dialog with exclamation icon.
        /// </summary>
        /// <param name="title">Title of the dialog</param>
        /// <param name="msg">Dialog message</param>
        /// <returns>Ok or Cancel</returns>
        public static DialogResult OkCancel(string title, string msg)
        {
            return MessageBox.Show(msg, title, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
        }
        /// <summary>
        /// Simplified all purpose dialog.
        /// </summary>
        /// <param name="title">Title of the dialog</param>
        /// <param name="msg">Dialog message</param>
        /// <param name="btn">Buttons to show</param>
        /// <param name="icn">Icon to show</param>
        /// <returns>DialogResult</returns>
        public static DialogResult Generic(string title, string msg, MessageBoxButtons btn, MessageBoxIcon icn)
        {
            return MessageBox.Show(msg, title, btn, icn);
        }
        /// <summary>
        /// Simplified information dialog with Ok button and information icon.
        /// </summary>
        /// <param name="title">Title of the dialog</param>
        /// <param name="msg">Dialog message</param>
        /// <returns>Ok</returns>
        public static DialogResult Info(string title, string msg)
        {
            return MessageBox.Show(msg, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
    /// <summary>
    /// Add Prefix and Suffix symbols
    /// </summary>
    public static class Sym
    {
        /// <summary>
        ///  ' - Prefix/Suffix
        /// </summary>
        /// <param name="obj">object</param>
        /// <returns>object</returns>
        public static object PQS(object obj)
        {
            return "'" + obj + "'";
        }
        /// <summary>
        /// '% - Prefix/Suffix
        /// </summary>
        /// <param name="obj">object</param>
        /// <returns>object</returns>
        public static object PQPS(object obj)
        {
            return "'%" + obj + "%'";
        }
        /// <summary>
        /// '% - Prefix
        /// </summary>
        /// <param name="obj">object</param>
        /// <returns>object</returns>
        public static object PQP(object obj)
        {
            return "'%" + obj;
        }
        /// <summary>
        /// '% - Suffix
        /// </summary>
        /// <param name="obj">object</param>
        /// <returns>object</returns>
        public static object QPS(object obj)
        {
            return obj + "%'";
        }
    }
}